package com.yxq.mdt.app.widgets;

import android.os.CountDownTimer;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxq.mdt.app.R;

public class TimeTool {
    private static CountDownTimer countDownTimer;

    public TimeTool(CountDownTimer countDownTimer) {
        TimeTool.countDownTimer = countDownTimer;
    }

    /**
     * @param playTime  开始时间
     * @param imageView 获取当前控件
     * @param timeTv    获取显示秒数
     */
    public static void TimeTool(String playTime, ImageView imageView, TextView timeTv) {

        countDownTimer = new CountDownTimer(Integer.parseInt(playTime) * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                timeTv.setText(millisUntilFinished / 1000 + "S");
            }

            @Override
            public void onFinish() {
                timeTv.setText(playTime + "S");
                imageView.setImageResource(R.mipmap.voice_note);
                countDownTimer.cancel();
            }
        };
    }

    public static void TimeNoImg(String playTime, TextView timeTv) {

        countDownTimer = new CountDownTimer(Integer.parseInt(playTime) * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                timeTv.setText(millisUntilFinished / 1000 + "S");
            }

            @Override
            public void onFinish() {
                timeTv.setText(playTime + "S");
                countDownTimer.cancel();
            }
        };
    }
}
